package org.example.Maskter;

import java.util.Random;

public class Main {
    public static void main(String[] args) {
        //初始化Master
        Master master = new Master(new Worker(),20);

        Random random = new Random();
        for (int i =0;i<=100;i++){
            Task t = new Task();;
            t.setId(i);
            t.setName("任务" +i);
            t.setPrice(random.nextInt(1000));
            //提交任务
            master.submitTask(t);
        }
        long start = System.currentTimeMillis();
        //执行任务，说有worker对象调用start方法
        master.execute();
        while (true){
            if (master.isStop()){
                long end = System.currentTimeMillis();
                int priceResult = master.getResult();
                System.out.println("最终结果"+priceResult+"执行时间"+(end-start));
                break;
            }
        }




    }
}
